﻿@model SuperLottery.AdminPortal.Models.DrawModel

@{
	Layout = "~/Views/Shared/_DrawLayout.cshtml";
	ViewBag.Title = "最新公告";
}


@using (Html.BeginForm())
{
	@Html.AntiForgeryToken()
	@Html.ValidationSummary(true)
    

	@Html.HiddenFor(model => model.Id)

	<table>
		<tr>
			<th>@Html.LabelFor(model => model.IssuerGame):</th>
			<td>@Html.DropDownListFor(model => model.IssuerGame, StaticDatas.IssuerGameItems)</td>
		</tr>
		<tr>
			<th>@Html.LabelFor(model => model.IssueNumber):</th>
			<td>@Html.EditorFor(model => model.IssueNumber)
				@Html.ValidationMessageFor(model => model.IssueNumber)
				<input id="btnCrawl" type="button" value="抓取" onclick="crawl()" /></td>
		</tr>
		<tr>
			<th>@Html.LabelFor(model => model.DrawDate):</th>
			<td>
				@Html.EditorFor(model => model.DrawDate)
				@Html.ValidationMessageFor(model => model.DrawDate)
			</td>
		</tr>
		<tr>
			<th>@Html.LabelFor(model => model.Numbers):</th>
			<td>
				@Html.EditorFor(model => model.Numbers)
				@Html.ValidationMessageFor(model => model.Numbers)</td>
		</tr>
		<tr>
			<th>@Html.LabelFor(model => model.BonusNumbers):</th>
			<td>
				@Html.EditorFor(model => model.BonusNumbers)
				@Html.ValidationMessageFor(model => model.BonusNumbers)</td>
		</tr>
		<tr>
			<th>@Html.LabelFor(model => model.SalesAmount):</th>
			<td>
				@Html.EditorFor(model => model.SalesAmount)
				@Html.ValidationMessageFor(model => model.SalesAmount)</td>
		</tr>
		<tr>
			<th>@Html.LabelFor(model => model.CumulativeAmount):</th>
			<td>
				@Html.EditorFor(model => model.CumulativeAmount)
				@Html.ValidationMessageFor(model => model.CumulativeAmount)</td>
		</tr>
		<tr>
			<th>&nbsp</th>
			<td>
				<table>
					<thead>
						<tr>
							<th>奖项</th>
							<th>人数</th>
							<th>奖金</th>
						</tr>
					</thead>
					<tbody>
						<tr>
							<td>@Html.EditorFor(model => model.Award1Name)</td>
							<td>
								@Html.EditorFor(model => model.Award1NumberOfWinners)</td>
							<td>
								@Html.EditorFor(model => model.Award1MoneyPerWinner)</td>
						</tr>
						<tr>
							<td>@Html.EditorFor(model => model.Award2Name)</td>
							<td>
								@Html.EditorFor(model => model.Award2NumberOfWinners)</td>
							<td>
								@Html.EditorFor(model => model.Award2MoneyPerWinner)</td>
						</tr>
						<tr>
							<td>@Html.EditorFor(model => model.Award3Name)</td>
							<td>
								@Html.EditorFor(model => model.Award3NumberOfWinners)</td>
							<td>
								@Html.EditorFor(model => model.Award3MoneyPerWinner)</td>
						</tr>
						<tr>
							<td>@Html.EditorFor(model => model.Award4Name)</td>
							<td>
								@Html.EditorFor(model => model.Award4NumberOfWinners)</td>
							<td>
								@Html.EditorFor(model => model.Award4MoneyPerWinner)</td>
						</tr>
						<tr>
							<td>@Html.EditorFor(model => model.Award5Name)</td>
							<td>
								@Html.EditorFor(model => model.Award5NumberOfWinners)</td>
							<td>
								@Html.EditorFor(model => model.Award5MoneyPerWinner)</td>
						</tr>
						<tr>
							<td>@Html.EditorFor(model => model.Award6Name)</td>
							<td>
								@Html.EditorFor(model => model.Award6NumberOfWinners)</td>
							<td>
								@Html.EditorFor(model => model.Award6MoneyPerWinner)</td>
						</tr>
						<tr>
							<td>@Html.EditorFor(model => model.Award7Name)</td>
							<td>
								@Html.EditorFor(model => model.Award7NumberOfWinners)</td>
							<td>
								@Html.EditorFor(model => model.Award7MoneyPerWinner)</td>
						</tr>
					</tbody>
				</table>
			</td>
		</tr>
		<tr>
			<th></th>
			<td></td>
		</tr>
	</table>

	<p>
		<input type="submit" value="Save" />
	</p>
	<script type="text/javascript">
		function crawl() {
			$("#btnCrawl").val("正在抓取中...");
			$("#btnCrawl").attr({ disabled: "disabled" });
			var url = "/api/crawler/get/" + $("#IssueNumber").val();
			if ($("#IssuerGame").val() == "福彩-七乐彩") {
				url = "/api/crawler/getqilecai/" + $("#IssueNumber").val();
			}
			jQuery.ajax({
				url: url,
				success: function (data) {
					$("#IssueNumber").val(data.IssueNumber);
					$("#DrawDate").val(data.DrawDate);
					$("#Numbers").val(data.Numbers);
					$("#BonusNumbers").val(data.BonusNumbers);
					$("#SalesAmount").val(data.SalesAmount);
					$("#CumulativeAmount").val(data.CumulativeAmount);
					$("#Award1Name").val(data.Award1Name);
					$("#Award1NumberOfWinners").val(data.Award1NumberOfWinners);
					$("#Award1MoneyPerWinner").val(data.Award1MoneyPerWinner);
					$("#Award2Name").val(data.Award2Name);
					$("#Award2NumberOfWinners").val(data.Award2NumberOfWinners);
					$("#Award2MoneyPerWinner").val(data.Award2MoneyPerWinner);
					$("#Award3Name").val(data.Award3Name);
					$("#Award3NumberOfWinners").val(data.Award3NumberOfWinners);
					$("#Award3MoneyPerWinner").val(data.Award3MoneyPerWinner);
					$("#Award4Name").val(data.Award4Name);
					$("#Award4NumberOfWinners").val(data.Award4NumberOfWinners);
					$("#Award4MoneyPerWinner").val(data.Award4MoneyPerWinner);
					$("#Award5Name").val(data.Award5Name);
					$("#Award5NumberOfWinners").val(data.Award5NumberOfWinners);
					$("#Award5MoneyPerWinner").val(data.Award5MoneyPerWinner);
					$("#Award6Name").val(data.Award6Name);
					$("#Award6NumberOfWinners").val(data.Award6NumberOfWinners);
					$("#Award6MoneyPerWinner").val(data.Award6MoneyPerWinner);
					$("#Award7Name").val(data.Award7Name);
					$("#Award7NumberOfWinners").val(data.Award7NumberOfWinners);
					$("#Award7MoneyPerWinner").val(data.Award7MoneyPerWinner);
				},
				complete: function (xhr, msg) {
					if (xhr.statusText != "OK") {
						alert(xhr.statusText);
					}
					$("#btnCrawl").removeAttr("disabled");
					$("#btnCrawl").val("抓取");
				}
			});
		}
	</script>
}